//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		account:app.setting.account,
		pagetitle:'工作台' + '-' + app.setting.title,
		
	},
	onReady: function (){
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (opt){
		var page=this;
		wx.setNavigationBarTitle({'title':page.data.pagetitle});
		var route=page.route;
		page.setData({
			route:route,
		});
		if(opt.fromuser){
			var path=route.slice(0,-6).split('/');
			app.access.plugin=path.shift();
			app.access.action=path.join('.');
			app.access.query =app.util.made_query(opt,true);
			app.access.op=opt.op?opt.op:'';
		}
		app.util.get(app.access,function(pagedata){
			//console.log('pagedata');console.log(pagedata);
			page.setData({
				pagedata:pagedata
			});
			if(!app.isShowSubMsg && pagedata.tmplIds && pagedata.tmplIds[0]){
				app.util.getsubmsgSet(pagedata.tmplIds,function(ShowSubMsg){
					if(ShowSubMsg){
						app.isShowSubMsg=true;
						page.setData({
							ShowSubMsg:true,
						});
					}
				});
			}
		});
	},
	//订阅消息
	SubscribeMessage: function () {
		var the=this
		var pagedata=the.data.pagedata
		the.setData({
				ShowSubMsg:false,
		});
		wx.requestSubscribeMessage({
			'tmplIds':pagedata.tmplIds,
			success:function (res) {
				console.log('SubscribeMessage success');console.log(res);
				if(res[pagedata.tmplIds[0]]=='accept'){
					
				}
			},
			fail:function (res) {
				console.log('SubscribeMessage fail');console.log(res);
			},
		})
	},
  	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	formSubmit:function(event){
		var data=event.detail.value;
		app.util.post('post',data);
	}
});